package svc

import (
	"github.com/tal-tech/go-zero/core/stores/redis"
	"github.com/tencentyun/cos-go-sdk-v5"
	"gitservice/internal/config"
	"net/http"
	"net/url"
)

type ServiceContext struct {
	Config config.Config
	Redis  *redis.Redis
	CosClient *cos.Client
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config: c,
		Redis:  redis.New(c.Redis.Host),
		CosClient: NewCosCLient(),
	}
}

func NewCosCLient() *cos.Client {
	// 将 examplebucket-1250000000 和 COS_REGION修改为真实的信息
	u, _ := url.Parse("https://quezr-1307637143.cos.ap-shanghai.myqcloud.com")
	// 用于Get Service 查询，默认全地域 service.cos.myqcloud.com
	b := &cos.BaseURL{BucketURL: u}
	// 1.永久密钥
	client := cos.NewClient(b, &http.Client{
		Transport: &cos.AuthorizationTransport{
			SecretID:  "AKIDUmoZ3GCqDJ8gy0lEQM1OVKuDF0UhdHfm",
			SecretKey: "sTmpc9MJzOVLuBBuMXR4QVJq65nFQLzM",
		},
	})
	return client
}
